﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;

namespace Zero.UControl.Demo.Views.UAdorner.Component
{
    public static class TransformUtil
    {
        public static void EnsureTransformGroup(UIElement element)
        {
            if (element.RenderTransform == null || !(element.RenderTransform is TransformGroup))
            {
                var group = new TransformGroup();
                group.Children.Add(new ScaleTransform(1, 1));
                group.Children.Add(new RotateTransform(0));
                group.Children.Add(new TranslateTransform(0, 0));
                element.RenderTransform = group;
                element.RenderTransformOrigin = new Point(0.5, 0.5); // 中心变换
            }
        }

        public static ScaleTransform GetScale(UIElement element)
            => ((TransformGroup)element.RenderTransform).Children.OfType<ScaleTransform>().First();

        public static RotateTransform GetRotate(UIElement element)
            => ((TransformGroup)element.RenderTransform).Children.OfType<RotateTransform>().First();

        public static TranslateTransform GetTranslate(UIElement element)
            => ((TransformGroup)element.RenderTransform).Children.OfType<TranslateTransform>().First();
    }

}
